from sklearn.datasets import load_iris,load_boston
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler,StandardScaler
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction import DictVectorizer
from sklearn.tree import DecisionTreeClassifier,export_graphviz
import pandas as pd

def mm():
    mm = MinMaxScaler(feature_range=(2,3))
    data = mm.fit_transform([[90,2,10,40],[60,4,15,45],[75,3,13,46]])
    print(data)
    return None
def stand():
    """
    标准化
    :return:
    """
    std = StandardScaler
    data = std.fit_transform()

    return None
def rd():
    """
    读取数据测试
    :return:
    """
    data=pd.read_csv("ex.csv")
    # print(data.head(10))
    x = data[['frame.time_delta','tcp.srcport','tcp.dstport','tcp.len','icmp','udp','tcp.flags','tcp.analysis.flags']]
    y = data[['an']]

    #print(y)
    # #缺失值处理
    x['icmp'].fillna(0,inplace= True)
    x['udp'].fillna(0, inplace=True)
    x['tcp.analysis.flags'].fillna(0, inplace=True)
    # #划分测试集
    x_train,x_test,y_train,y_test= train_test_split(x,y,test_size=0.25)
    # #特征工程处理
    dict =DictVectorizer(sparse=False)
    x_train=dict.fit_transform(x_train.to_dict(orient="records"))
    print(dict.get_feature_names())
    x_test=dict.transform(x_test.to_dict(orient="records"))
    #print(x_train)
    #用决策树预测
    dec = DecisionTreeClassifier()
    dec.fit(x_train,y_train)
    #预测准确率
    print("预测成功率为",dec.score(x_test,y_test))

    return None

if __name__ == "__main__":
    rd()
5